package com.proba.annotations.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.samples.mvc.basic.sluzba.SluzbaView;

import com.proba.annotations.SluzbaDAO;
import com.proba.annotations.pojo.Sluzba;

public class SluzbaHibernateDAO extends
		AbstractHibernateDAO<Sluzba, Long> implements
		SluzbaDAO {

	public List<Sluzba> findBySluzba(String sluzba) {
		return findByCriteria(Restrictions.eq("investitor", sluzba));
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<Sluzba> findByFilterParams(int startIndex, int pageSize,
			Long id, String sluzba) {
		Criteria crit = getCriteria(startIndex, pageSize);
		if (id != null) {
			crit.add(Restrictions.eq("id", id));
			return crit.list();
		}
		if (sluzba != null && !sluzba.isEmpty()) {
			crit.add(like("investitor", sluzba));
		}
		return crit.list();
	}

}
